<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><script>(()=>{const e=navigator.serviceWorker;e?e.register("/sw.js").then((async e=>{console.log("SWPP 注册成功");try{await e.periodicSync.register("update",{minInterval:864e5})}catch(e){console.log("Periodic Sync 注册失败",e)}})).catch((e=>console.error("SWPP 注册失败",e))):console.warn("当前浏览器不支持 SW")})()</script><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><title>twikoo仿段落评论，实现快速评论功能 | LiuShen's Blog</title><meta name="author" content="LiuShen"><meta name="copyright" content="LiuShen"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="robots" content="index, follow"><meta name="description" content="先前twikoo的讨论群中提出了一个功能，类似于小说之类的段落评论功能，我思考了一下，感觉这个功能很有意思，评论起来比评论区快多了，于是用我为数不多的JS知识，尝试实现了一下，没想到还真让我给搞出来了。"><meta property="og:type" content="article"><meta property="og:title" content="twikoo仿段落评论，实现快速评论功能"><meta property="og:url" content="https://blog.liushen.fun/posts/73765344/"><meta property="og:site_name" content="LiuShen's Blog"><meta property="og:description" content="先前twikoo的讨论群中提出了一个功能，类似于小说之类的段落评论功能，我思考了一下，感觉这个功能很有意思，评论起来比评论区快多了，于是用我为数不多的JS知识，尝试实现了一下，没想到还真让我给搞出来了。"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://p.liiiu.cn/i/2024/04/19/6621c4a8c099b.png"><meta property="article:published_time" content="2024-04-20T15:07:00.000Z"><meta property="article:modified_time" content="2024-04-19T07:07:00.000Z"><meta property="article:author" content="LiuShen"><meta property="article:tag" content="功能"><meta property="article:tag" content="CSS"><meta property="article:tag" content="Hexo"><meta property="article:tag" content="twikoo"><meta property="article:tag" content="JavaScript"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://p.liiiu.cn/i/2024/04/19/6621c4a8c099b.png"><link rel="shortcut icon" href="/favicon.ico"><link rel="canonical" href="https://blog.liushen.fun/posts/73765344/"><link rel="preconnect" href="https://jsd.liiiu.cn"><meta name="baidu-site-verification" content="codeva-i2bF9bXDJs"><meta name="sogou_site_verification" content="1rIjtK6RhE"><meta name="360-site-verification" content="b9a9f96ae38a1932a326f8ba255cc74b"><meta name="msvalidate.01" content="F7C246820EB04DD140494C98F93A97C7"><meta name="google-site-verification" content="VH3ZE6m42MZDqpTY2tD-XoxDt9iUj2HoiC3W2neB7F4"><link rel="manifest" href="/manifest.json"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/config/img/pwa/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/config/img/pwa/favicon-16x16.png"><link rel="mask-icon" href="/config/img/pwa/favicon-mask.svg" color="#5bbad5"><link rel="stylesheet" href="/css/index.css?v=5.0.0"><link rel="stylesheet" href="/css/custom.css?v=5.0.0"><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/@fortawesome/fontawesome-free@6.7.2/css/all.min.css"><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/@fancyapps/ui@5.0.36/dist/fancybox/fancybox.min.css" media="print" onload='this.media="all"'><script>(()=>{const e={set:(e,t,o)=>{if(!o)return;const n=Date.now()+864e5*o;localStorage.setItem(e,JSON.stringify({value:t,expiry:n}))},get:e=>{const t=localStorage.getItem(e);if(!t)return;const{value:o,expiry:n}=JSON.parse(t);if(!(Date.now()>n))return o;localStorage.removeItem(e)}};window.btf={saveToLocal:e,getScript:(e,t={})=>new Promise(((o,n)=>{const a=document.createElement("script");a.src=e,a.async=!0,Object.entries(t).forEach((([e,t])=>a.setAttribute(e,t))),a.onload=a.onreadystatechange=()=>{a.readyState&&!/loaded|complete/.test(a.readyState)||o()},a.onerror=n,document.head.appendChild(a)})),getCSS:(e,t)=>new Promise(((o,n)=>{const a=document.createElement("link");a.rel="stylesheet",a.href=e,t&&(a.id=t),a.onload=a.onreadystatechange=()=>{a.readyState&&!/loaded|complete/.test(a.readyState)||o()},a.onerror=n,document.head.appendChild(a)})),addGlobalFn:(e,t,o=!1,n=window)=>{const a=n.globalFn||{};a[e]=a[e]||{},o&&a[e][o]||(a[e][o||Object.keys(a[e]).length]=t,n.globalFn=a)}};const t=()=>{document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},o=()=>{document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};btf.activateDarkMode=t,btf.activateLightMode=o;const n=e.get("theme"),a=(new Date).getHours();void 0===n?a<=6||a>=18?t():o():"light"===n?o():t();const r=e.get("aside-status");void 0!==r&&document.documentElement.classList.toggle("hide-aside","hide"===r);/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})()</script><script>const GLOBAL_CONFIG={root:"/",algolia:{appId:"7IX3UBC6JW",apiKey:"4ac2846352e499675081f1277fb961c1",indexName:"My Blog",hitsPerPage:6,languages:{input_placeholder:"搜索全站文章",hits_empty:"未找到符合您查询的内容：${query}",hits_stats:"找到 ${hits} 条结果，耗时 ${time} 毫秒"}},localSearch:void 0,translate:{defaultEncoding:2,translateDelay:0,msgToTraditionalChinese:"繁",msgToSimplifiedChinese:"簡"},noticeOutdate:{limitDay:365,position:"top",messagePrev:"本篇文章从发布到现在已经隔了",messageNext:"天了，里面的内容可能过期了，你要自己甄别一下哟👉👈"},highlight:{plugin:"highlight.js",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:400,highlightFullpage:!1,highlightMacStyle:!0},copy:{success:"😋复制啦！请注意版权信息呀！",error:"😪呜呜，复制失败了！",noSupport:"🤐浏览器不支持呢，你用的啥玩意？"},relativeDate:{homepage:!1,post:!1},runtime:"天",dateSuffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:1e3,languages:{author:"作者: LiuShen",link:"链接: ",source:"来源: LiuShen's Blog",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"已切换为繁体中文",cht_to_chs:"已切换为简体中文",day_to_night:"已切换为深色模式",night_to_day:"已切换为浅色模式",bgLight:"rgba(255, 255, 255, 0.509)",bgDark:"rgba(48, 48, 48, 0.509)",position:"top-right"},infinitegrid:{js:"https://jsd.liiiu.cn/npm/@egjs/infinitegrid@4.12.0/dist/infinitegrid.min.js",buttonText:"加载更多"},isPhotoFigcaption:!0,islazyload:!0,isAnchor:!1,percent:{toc:!0,rightside:!1},autoDarkmode:!1}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"twikoo仿段落评论，实现快速评论功能",isPost:!0,isHome:!1,isHighlightShrink:void 0,isToc:!0,postUpdate:"2024-04-19 15:07:00"}</script><link rel="stylesheet" href="https://jsd.liiiu.cn/gh/willow-god/Sharding-fonts/Yozai-Medium/result.min.css"><link rel="stylesheet" href="/config/memos/memos.css"><script defer src="/sw-dom.js"></script><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/swiper@11.1.14/swiper-bundle.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="/config/swiper/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 7.3.0"><link rel="alternate" href="/atom.xml" title="LiuShen's Blog" type="application/atom+xml"></head><body><div class="float-box right top"></div><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><img class="load-image" src="" data-lazy-src="/config/img/preloader.gif" alt=""></div><script async>(()=>{const e=document.getElementById("loading-box"),d=document.body,t=()=>{d.style.overflow="",e.classList.add("loaded")},n=()=>{d.style.overflow="hidden",e.classList.remove("loaded")};n();let o=!1;window.addEventListener("load",(()=>{o||(t(),o=!0)})),setTimeout((()=>{o||(t(),o=!0)}),5e3),window.addEventListener("load",(()=>{t()})),setTimeout((function(){t()}),3e3),document.getElementById("loading-box").addEventListener("click",(()=>{t()})),document.addEventListener("pjax:send",(()=>{n()})),document.addEventListener("pjax:complete",(()=>{t()}))})()</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="add-menu-container"><div id="travellings"><a class="site-page" href="https://www.travellings.cn/go.html" title="友链接力-随机开往" target="_blank" rel="noopener nofollow"><i class="fa-solid fa-bus fa-fw"></i></a></div><div id="ten-years"><a class="site-page" href="https://foreverblog.cn/go.html" title="友链接力-十年之约" target="_blank" rel="noopener nofollow"><i class="fa-brands fa-nfc-symbol fa-fw"></i></a></div></div><div class="is-center" id="sidebar-avatar"><div class="avatar-img is-center"><img class="mood-icon" src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/14/67d301461a24a.webp" alt="🤤" onerror='this.onerror=null,this.src="/img/friend_404.gif"'><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/13/67d2fc82d329c.webp" onerror='this.onerror=null,this.src="/img/friend_404.gif"' alt="avatar"></div><div class="author-info__name">LiuShen</div></div><div class="site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">72</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">98</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/willow-god"><i class="fab fa-github"></i><span>Follow Me 🛫</span></a><div class="menus_items visible"><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fas fa-home"></i> <span>导航</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.liushen.fun/"><i class="fa-fw fa-solid fa-house-flag"></i> <span>个人主页</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://xc.liushen.fun/"><i class="fa-fw fa fa-camera-retro"></i> <span>个人相册</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-graduation-cap"></i> <span>整理</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i> <span>时光卷轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i> <span>文章标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i> <span>文章分类</span></a></li><li><a class="site-page child" href="/charts/"><i class="fa-fw fa-solid fa-chart-pie"></i> <span>文章通览</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-user-group"></i> <span>友人</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/link/"><i class="fa-fw fas fa-link"></i> <span>友链展示</span></a></li><li><a class="site-page child" href="/addlink/"><i class="fa-fw fa fa-at"></i> <span>友链申请</span></a></li><li><a class="site-page child" href="/fcircle/"><i class="fa-fw fa-solid fa-circle-nodes"></i> <span>朋友动态</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-paper-plane"></i> <span>留言</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa-solid fa-chalkboard"></i> <span>留言白板</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://mm.liushen.fun/"><i class="fa-fw fa-solid fa-pen-nib"></i> <span>提笔摘星</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-stethoscope"></i> <span>分享</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gist.liushen.fun/"><i class="fa-fw fa-solid fa-code"></i> <span>代码片段</span></a></li><li><a class="site-page child" href="/subscribe/"><i class="fa-fw fa-solid fa-rss"></i> <span>订阅本站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://pan.liushen.fun/"><i class="fa-fw fa-solid fa-laptop-file"></i> <span>清羽云盘</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-list"></i> <span>关于</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/about/"><i class="fa-fw fa fa-address-card"></i> <span>站长资料</span></a></li><li><a class="site-page child" href="/shuoshuo/"><i class="fa-fw fa fa-commenting"></i> <span>日常说说</span></a></li><li><a class="site-page child" href="/devices/"><i class="fa-fw fa-solid fa-tachograph-digital"></i> <span>我的设备</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image:url(https://p.liiiu.cn/i/2024/04/19/6621c4a8c099b.png)"><nav id="nav"><div class="more-app-btn"><i class="fa-solid fa-fingerprint fa-fw"></i><div class="more-app-list-groups"><div class="more-app-list-groups-container"><div class="more-app-list-group"><div class="more-app-list-title">🦄常用网站</div><div class="more-app-list"><a class="more-app-list-item" href="https://www.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-house"></i><span class="more-app-item-text">个人主页</span></a><a class="more-app-list-item" href="https://blog.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-blog"></i><span class="more-app-item-text">个人博客</span></a><a class="more-app-list-item" href="https://xc.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-image"></i><span class="more-app-item-text">个人相册</span></a><a class="more-app-list-item" href="https://github.com/willow-god" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-brands fa-github"></i><span class="more-app-item-text">Github</span></a></div></div><div class="more-app-list-group"><div class="more-app-list-title">😎周边站点</div><div class="more-app-list"><a class="more-app-list-item" href="https://gist.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-code"></i><span class="more-app-item-text">代码片段</span></a><a class="more-app-list-item" href="https://mm.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-pen-nib"></i><span class="more-app-item-text">提笔摘星</span></a><a class="more-app-list-item" href="https://pan.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-cloud"></i><span class="more-app-item-text">清羽云盘</span></a><a class="more-app-list-item" href="https://um.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-people-group"></i><span class="more-app-item-text">访客统计</span></a><a class="more-app-list-item" href="https://img.liiiu.cn/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-images"></i><span class="more-app-item-text">清羽图床</span></a><a class="more-app-list-item" href="https://chat.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-robot"></i><span class="more-app-item-text">清羽AI</span></a><a class="more-app-list-item" href="https://bsz.liiiu.cn/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-chart-pie"></i><span class="more-app-item-text">不蒜计数</span></a><a class="more-app-list-item" href="https://status.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-server"></i><span class="more-app-item-text">服务检测</span></a></div></div><div class="more-app-list-group"><div class="more-app-list-title">🚁实用工具</div><div class="more-app-list"><a class="more-app-list-item" href="https://tmail.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-envelope"></i><span class="more-app-item-text">临时邮箱</span></a><a class="more-app-list-item" href="https://hot.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-fire"></i><span class="more-app-item-text">每日热榜</span></a><a class="more-app-list-item" href="https://cover.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-eye"></i><span class="more-app-item-text">封面设计</span></a><a class="more-app-list-item" href="https://mini-cover.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-image"></i><span class="more-app-item-text">迷你封面</span></a><a class="more-app-list-item" href="https://icon.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-icons"></i><span class="more-app-item-text">万能图标</span></a><a class="more-app-list-item" href="https://draw.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-paintbrush"></i><span class="more-app-item-text">灵感白板</span></a><a class="more-app-list-item" href="https://mindmap.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-network-wired"></i><span class="more-app-item-text">思维导图</span></a><a class="more-app-list-item" href="https://share.liushen.fun/#/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-share-nodes"></i><span class="more-app-item-text">内容中转</span></a></div></div></div></div></div><span id="blog-info"><a class="nav-site-title" href="/" title="LiuShen's Blog"><span class="site-name">LiuShen</span></a></span><div id="menus"></div><div class="menus_items visible"><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fas fa-home"></i> <span>导航</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.liushen.fun/"><i class="fa-fw fa-solid fa-house-flag"></i> <span>个人主页</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://xc.liushen.fun/"><i class="fa-fw fa fa-camera-retro"></i> <span>个人相册</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-graduation-cap"></i> <span>整理</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i> <span>时光卷轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i> <span>文章标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i> <span>文章分类</span></a></li><li><a class="site-page child" href="/charts/"><i class="fa-fw fa-solid fa-chart-pie"></i> <span>文章通览</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-user-group"></i> <span>友人</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/link/"><i class="fa-fw fas fa-link"></i> <span>友链展示</span></a></li><li><a class="site-page child" href="/addlink/"><i class="fa-fw fa fa-at"></i> <span>友链申请</span></a></li><li><a class="site-page child" href="/fcircle/"><i class="fa-fw fa-solid fa-circle-nodes"></i> <span>朋友动态</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-paper-plane"></i> <span>留言</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa-solid fa-chalkboard"></i> <span>留言白板</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://mm.liushen.fun/"><i class="fa-fw fa-solid fa-pen-nib"></i> <span>提笔摘星</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-stethoscope"></i> <span>分享</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gist.liushen.fun/"><i class="fa-fw fa-solid fa-code"></i> <span>代码片段</span></a></li><li><a class="site-page child" href="/subscribe/"><i class="fa-fw fa-solid fa-rss"></i> <span>订阅本站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://pan.liushen.fun/"><i class="fa-fw fa-solid fa-laptop-file"></i> <span>清羽云盘</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-list"></i> <span>关于</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/about/"><i class="fa-fw fa fa-address-card"></i> <span>站长资料</span></a></li><li><a class="site-page child" href="/shuoshuo/"><i class="fa-fw fa fa-commenting"></i> <span>日常说说</span></a></li><li><a class="site-page child" href="/devices/"><i class="fa-fw fa-solid fa-tachograph-digital"></i> <span>我的设备</span></a></li></ul></div></div><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center><div id="nav-right"><div id="travellings"><a class="site-page" href="https://www.travellings.cn/go.html" title="友链接力-随机开往" target="_blank" rel="noopener nofollow"><i class="fa-solid fa-bus fa-fw"></i></a></div><div id="ten-years"><a class="site-page" href="https://foreverblog.cn/go.html" title="友链接力-十年之约" target="_blank" rel="noopener nofollow"><i class="fa-brands fa-nfc-symbol fa-fw"></i></a></div><div id="random"><a class="site-page" href="javascript:randomPost()" title="随机前往一个文章"><i class="fa-solid fa-shuffle fa-fw"></i></a></div><div id="search-button"><span class="site-page social-icon search"><i class="fas fa-search fa-fw"></i></span></div><div id="toggle-menu"><span class="site-page" href="javascript:void(0);" title="展开菜单"><i class="fas fa-indent fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">twikoo仿段落评论，实现快速评论功能</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-04-20T15:07:00.000Z" title="发表于 2024-04-20 23:07:00">2024-04-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-04-19T07:07:00.000Z" title="更新于 2024-04-19 15:07:00">2024-04-19</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/website/">博客管理</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">总字数:</span><span class="word-count">4.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>18分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span><span class="post-meta-separator">|</span><span class="post-meta-commentcount"><i class="far fa-comments fa-fw post-meta-icon"></i><span class="post-meta-label">评论数:</span><a href="/posts/73765344/#post-comment"><span id="ArtalkCount"><i class="fa-solid fa-spinner fa-spin"></i></span></a></span></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s58 18 88 18 58-18 88-18 58 18 88 18v44h-352Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><div class="ai-summary"><div class="ai-head"><div class="ai-head-left"><div class="ai-circle ai-circle-1"></div><div class="ai-circle ai-circle-2"></div><div class="ai-circle ai-circle-3"></div></div><div class="ai-head-right"><a class="ai-about-ai" href="/posts/40702a0d/">关于AI</a></div></div><div class="ai-explanation" style="display:block" data-summary="这里是清羽AI，这篇文章介绍了如何使用Twikoo实现段落评论功能。作者首先讨论了在Twikoo中实现段落评论的挑战，因为Twikoo默认不支持段落级别的评论，而其他平台如番茄小说和Hexo可以实现。为了解决这个问题，作者提出了一种仿段落评论的方法，利用点击评论按钮后在评论区添加引用功能，使得用户可以针对选中的段落进行评论。文章详细阐述了实现这一功能的具体步骤，包括添加右键菜单中的评论按钮、实现亮暗模式和高分辨率适配、动画效果适配、自动将节选段落放置在评论框中、解决文本中含有回车导致函数失效的问题以及弹窗问题的修复。最后，作者提供了一个完整的实现方案，包括加载Twikoo库、创建遮罩层和弹窗、关闭弹窗并移除遮罩层以及点击弹窗外部关闭弹窗的功能。整个实现过程详细而具体，为读者提供了清晰的指导。">清羽AI正在绞尽脑汁想思路ING···</div><div class="ai-title"><div class="ai-title-left"><i class="fa-brands fa-slack"></i><div class="ai-title-text">清羽のAI摘要</div></div><div class="ai-tag" id="ai-tag">GLM-4-Flash</div></div></div><h2 id="碎碎念"><a href="#碎碎念" class="headerlink" title="碎碎念"></a>碎碎念</h2><p>前几天在twikoo的交流群中，有人提到了这样一个问题：twikoo可以实现段落评论吗？我想了一下，下载了个番茄小说发现，他们都是按照每一行的内容分别进行评论的，Hexo可以实现类似于每一段落一个Url，也就是#[段落名]的格式，但是Twikoo并不能将这些段落分开，而且本来评论就很少了，（这么一分就都看不见了）。所以我想是否可以利用我的说说页面中的，点击评论按钮后后会在评论区添加一个：&gt; + “文本”，从而实现类似引用的功能，那么也就实现了仿段落评论，同时所有的评论都会在评论区显示，避免了因为都在段落评论而导致主评论区没人的尴尬局面。</p><div class="tabs"><div class="nav-tabs"><button type="button" class="tab active">问题提出</button><button type="button" class="tab">番茄小说</button><button type="button" class="tab">Hexo段落链接</button><button type="button" class="tab">说说卡片回复</button><button type="button" class="tab">卡片回复效果</button></div><div class="tab-contents"><div class="tab-item-content active"><div class="chatContainer"><div class="chatBoxTitle"><i class="fa-solid fa-angle-left"></i><span class="chatTitleText">群聊的聊天记录</span><div class="chatBoxIcons"><i class="fa-solid fa-user"></i><i class="fa-solid fa-bars"></i></div></div><div class="chatBox"><div class="chatItem"><img class="chatAvatar no-lightbox" src="" data-lazy-src="https://i.p-i.vip/30/20240920-66ed9a608c2cf.png"><div class="chatContentWrapper"><b class="chatName">哈哈哈</b><div class="chatContent">可以支持对文章某一行进行评论吗？</div></div></div><div class="chatItem"><img class="chatAvatar no-lightbox" src="" data-lazy-src="https://i.p-i.vip/30/20240920-66ed9a608c2cf.png"><div class="chatContentWrapper"><b class="chatName">哈哈哈</b><div class="chatContent">某一段落</div></div></div><div class="chatItem"><img class="chatAvatar no-lightbox" src="" data-lazy-src="https://i.p-i.vip/30/20240920-66ed9a608c2cf.png"><div class="chatContentWrapper"><b class="chatName">哈哈哈</b><div class="chatContent">类似这样</div></div></div><div class="chatItem"><img class="chatAvatar no-lightbox" src="" data-lazy-src="https://i.p-i.vip/30/20240920-66ed9a608c2cf.png"><div class="chatContentWrapper"><b class="chatName">哈哈哈</b><div class="chatContent">就是对文章某一处进行评论</div></div></div><div class="chatItem"><img class="chatAvatar no-lightbox" src="" data-lazy-src="https://i.p-i.vip/30/20240920-66ed9a608c2cf.png"><div class="chatContentWrapper"><b class="chatName">哈哈哈</b><div class="chatContent">就和小说很像（（（</div></div></div><div class="chatItem me"><img class="chatAvatar no-lightbox" src="" data-lazy-src="https://p.liiiu.cn/i/2024/03/29/66061417537af.png"><div class="chatContentWrapper"><b class="chatName">LiuShen</b><div class="chatContent">欸？你别说，你还真别说，好像有搞头啊！</div></div></div></div></div></div><div class="tab-item-content"><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/6621ca8f6e96c.jpeg" alt="番茄小说"></p></div><div class="tab-item-content"><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/6621cb1e140c9.png" alt="Hexo段落链接"></p></div><div class="tab-item-content"><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/6621cb5f314bc.png" alt="说说卡片回复"></p></div><div class="tab-item-content"><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/6621cc37d1e17.png" alt="回复效果"></p></div></div><div class="tab-to-top"><button type="button" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div><h2 id="内容简述"><a href="#内容简述" class="headerlink" title="内容简述"></a>内容简述</h2><ol><li>实现亮暗模式适配</li><li>实现高分辨率适配，设置上下阈值，基本确保不会超出屏幕</li><li>动画效果适配</li><li>自动将节选段落放置在评论框中</li><li>解决文本中含有回车导致函数失效的问题</li><li>解决好友<a target="_blank" rel="external nofollow noopener noreferrer" href="/safego/?u=aHR0cHM6Ly9ibG9nLmltc3l5LnRvcC8">imsyy</a>提出的弹窗中再次点击打开弹窗会导致无法关闭的问题:<a href="#%E6%B7%BB%E5%8A%A0%E6%8C%89%E9%92%AE">点击跳转</a></li><li>解决好友<a target="_blank" rel="external nofollow noopener noreferrer" href="/safego/?u=aHR0cHM6Ly9ibG9nLmltc3l5LnRvcC8">imsyy</a>提出的弹窗中点击刷新按钮会退出的问题:<a href="#CSS%E6%B7%BB%E5%8A%A0">点击跳转</a></li></ol><ul><li><p><strong>欢迎测试</strong>：请选中你想评论的段落并右键，点击：“评论选中段落”按钮即可看到</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/66223e532efab.png" alt="测试方法"></p></li></ul><h2 id="实现功能"><a href="#实现功能" class="headerlink" title="实现功能"></a>实现功能</h2><h3 id="添加按钮"><a href="#添加按钮" class="headerlink" title="添加按钮"></a>添加按钮</h3><p>要实现回复功能，首先需要有回复按钮呀，我们先考虑一下逻辑，什么情况需要回复按钮？经过设计，我决定将按钮添加在右键菜单中，并且是文章页，且需要选中文字右键才有效果（因为你不选中文字回复什么段落），我们先添加按钮，如果没有进行魔改右键菜单的请按照别人的教程进行魔改，可以参考下面这些链接（以下方法不分先后，都可以使用）</p><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9ibG9nLm1ldGEtY29kZS50b3AvMjAyMi8wNi8xMi8yMDIyLTY4Lw" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">【Hexo博客】魔改美化 Butterfly 主题右键菜单</div><div class="tag-link-sitename">百里飞洋</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9ibG9nLnpoaGVvLmNvbS9wLzVlOTMxYjY1Lmh0bWw" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">Butterfly魔改：自定义右键菜单</div><div class="tag-link-sitename">张洪Heo</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9tZXVpY2F0LmNvbS9ibG9nLzg2L2luZGV4Lmh0bWw" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">Butterfly的魔改教程：右键菜单</div><div class="tag-link-sitename">爱吃肉的猫·亦小封</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><p>以上均可以实现右键菜单的魔改，推荐百里飞洋的文章，因为有复制功能，本教程也是基于他的进行修改，这里不再详细讲解，我们直接进入添加段落回复功能。</p><p>在<code>"[root]\themes\butterfly\layout\includes\rightmenu.pug"</code>文件中修改复制按钮部分：</p><figure class="highlight diff"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">#rightMenu</span><br><span class="line">    .rightMenu-group.rightMenu-small</span><br><span class="line">        .rightMenu-item#menu-backward</span><br><span class="line">            i.fa-solid.fa-arrow-left</span><br><span class="line">        .rightMenu-item#menu-forward</span><br><span class="line">            i.fa-solid.fa-arrow-right</span><br><span class="line">        .rightMenu-item#menu-refresh</span><br><span class="line">            i.fa-solid.fa-arrow-rotate-right</span><br><span class="line">        .rightMenu-item#menu-home</span><br><span class="line">            i.fa-solid.fa-house</span><br><span class="line">    .rightMenu-group.rightMenu-line.hide#menu-text</span><br><span class="line"><span class="addition">+        a.rightMenu-item#copy(href="javascript:rm.copySelect();")</span></span><br><span class="line"><span class="deletion">-        a.rightMenu-item(href="javascript:rm.copySelect();")</span></span><br><span class="line">            i.fa-solid.fa-copy</span><br><span class="line">            span='复制选中文字'</span><br><span class="line"><span class="addition">+        a.rightMenu-item#reply(href="javascript:rm.replySelect();")</span></span><br><span class="line"><span class="addition">+            i.fa-regular.fa-comment</span></span><br><span class="line"><span class="addition">+            span='评论选中段落'</span></span><br><span class="line">    .rightMenu-group.rightMenu-line.rightMenuOther</span><br><span class="line">        a.rightMenu-item.menu-link(href='/archives/')</span><br><span class="line">            i.fa-solid.fa-archive</span><br><span class="line">            span='文章时间线'</span><br><span class="line">        a.rightMenu-item.menu-link(href='/categories/')</span><br><span class="line">            i.fa-solid.fa-folder-open</span><br><span class="line">            span='文章分大类'</span><br><span class="line">        a.rightMenu-item.menu-link(href='/tags/')</span><br><span class="line">            i.fa-solid.fa-tags</span><br><span class="line">            span='文章小标签'</span><br><span class="line">    .rightMenu-group.rightMenu-line.rightMenuNormal</span><br><span class="line">        a.rightMenu-item.menu-link#menu-radompage(href='/comment/')</span><br><span class="line">            i.fa-solid.fa-shoe-prints</span><br><span class="line">            span='随心留言板'</span><br><span class="line">        .rightMenu-item#menu-translate</span><br><span class="line">            i.fa-solid.fa-earth-asia</span><br><span class="line">            span='繁简模式切换'</span><br><span class="line">        .rightMenu-item#menu-darkmode</span><br><span class="line">            i.fa-solid.fa-moon</span><br><span class="line">            span='切换亮暗模式'</span><br><span class="line">        .rightMenu-item#menu-live2dvisibility</span><br><span class="line">            i.fa-solid.fa-cat</span><br><span class="line">            span='小猫显示隐藏'</span><br><span class="line">        .rightMenu-item#menu-print</span><br><span class="line">            i.fa-solid.fa-print.fa-fw</span><br><span class="line">            span='打印整个页面'</span><br><span class="line">        a.rightMenu-item.menu-link#statement(href='/statement/')</span><br><span class="line">            i.fa-regular.fa-copyright.fa-fw</span><br><span class="line">            span='网站声明'</span><br><span class="line">#rightmenu-mask</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>如上代码所示，为了更好的自定义每个元素，我们给原本的复制按钮添加了一个<code>"#copy"</code>表示ID，并在复制的下面添加了回复段落功能，样式前面已经添加了，我们这里不需要进行修改了，只添加元素即可，去掉加减号即为正常缩进，<code>rm.replySelect()</code>为我们的执行函数。</p><p>下面我们来控制他的显示和隐藏：</p><p>在自定义JS文件中，修改<code>"window.oncontextmenu = function (event)"</code>部分代码：</p><div class="note note-info"><div class="note-header"><i class="note-icon fa-regular fa-circle-check"></i> <span class="note-title">更新记录</span></div><div class="note-content"><p>下方代码2024-04-20更新：第九行添加判断，判断页面中是否存在popup元素</p></div></div><figure class="highlight diff"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">window.oncontextmenu = function (event) {</span><br><span class="line"><span class="addition">+    $('#menu-text #copy').hide();</span></span><br><span class="line"><span class="addition">+    $('#menu-text #reply').hide();</span></span><br><span class="line"><span class="addition">+    //如果有文字选中，则显示 文字选中相关的菜单项</span></span><br><span class="line"><span class="addition">+    if(document.getSelection().toString()){</span></span><br><span class="line"><span class="addition">+        $('#menu-text #copy').show();</span></span><br><span class="line"><span class="addition">+    }</span></span><br><span class="line"><span class="addition">+    const currentPath = window.location.pathname;</span></span><br><span class="line"><span class="addition">+    if (document.getSelection().toString() &amp;&amp; currentPath.startsWith('/posts/')) {</span></span><br><span class="line"><span class="addition">+        // 如果页面中没有弹窗元素，则显示按钮并调用函数显示弹窗</span></span><br><span class="line"><span class="addition">+		if (!document.getElementById('popup')) {</span></span><br><span class="line"><span class="addition">+			$('#menu-text #reply').show();</span></span><br><span class="line"><span class="addition">+		}</span></span><br><span class="line"><span class="addition">+    }</span></span><br><span class="line"><span class="deletion">-    $('.rightMenu-group.hide').hide();</span></span><br><span class="line"><span class="deletion">-    //如果有文字选中，则显示 文字选中相关的菜单项</span></span><br><span class="line"><span class="deletion">-    if(document.getSelection().toString()){</span></span><br><span class="line"><span class="deletion">-        $('#menu-text').show();</span></span><br><span class="line"><span class="deletion">-    }</span></span><br><span class="line">    if (document.body.clientWidth &gt; 768) {</span><br><span class="line">        let pageX = event.clientX + 10;	</span><br><span class="line">        let pageY = event.clientY;</span><br><span class="line">        let $rightMenuNormal = $(".rightMenuNormal");</span><br><span class="line">        let $rightMenuOther = $(".rightMenuOther");</span><br><span class="line">        let $rightMenuReadmode = $("#menu-readmode");</span><br><span class="line">        $rightMenuNormal.show();</span><br><span class="line">        $rightMenuOther.show();</span><br><span class="line">        rm.reloadrmSize();</span><br><span class="line">        if (pageX + rmWidth &gt; window.innerWidth) {</span><br><span class="line">            pageX -= rmWidth;</span><br><span class="line">        }</span><br><span class="line">        if (pageY + rmHeight &gt; window.innerHeight) {</span><br><span class="line">            pageY -= rmHeight;</span><br><span class="line">        }</span><br><span class="line">        rm.showRightMenu(true, pageY, pageX);</span><br><span class="line">        $('#rightmenu-mask').attr('style', 'display: flex');</span><br><span class="line">        return false;</span><br><span class="line">    }</span><br><span class="line">};</span><br></pre></td></tr></tbody></table></figure><p>此时就可以基本测试出我们的逻辑是否正常了，hexo三联，在文章页选中文字右键才能看见我们的回复段落功能按钮出现，其他方式均不能触发。</p><div class="tabs"><div class="nav-tabs"><button type="button" class="tab active">非文章页不选中</button><button type="button" class="tab">非文章页选中</button><button type="button" class="tab">文章页选中</button></div><div class="tab-contents"><div class="tab-item-content active"><p>非文章页不选中文字时，右键复制及回复均无法显示</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/6622061738a79.png" alt="非文章页不选中"></p></div><div class="tab-item-content"><p>非文章页选中文字仅会触发复制</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/66220693b918b.png" alt="非文章页选中"></p></div><div class="tab-item-content"><p>仅仅在文章页且选中文字的情况下才可以触发该动作</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/662206f7b17ce.png" alt="文章页选中"></p></div></div><div class="tab-to-top"><button type="button" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div><h3 id="实现函数"><a href="#实现函数" class="headerlink" title="实现函数"></a>实现函数</h3><p>这里我会咯嗦我的探索过程，请不想看只想实现功能的铁铁直接跳转到第三部分按照教程顺序实现即可。</p><h4 id="妥协方案"><a href="#妥协方案" class="headerlink" title="妥协方案"></a>妥协方案</h4><p>下面我们需要实现该功能，刚开始我选择的时使用和说说页面类似的效果，当点击评论后，找到评论区输入框，将选中文字放到输入框中，进行类似于回复段落的效果，但是由于我设置的懒加载，当评论区没有滚入到页面视野内时不会自动加载，会导致如下查找输入框语句失败：</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> commentBox = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">".el-textarea__inner"</span>);</span><br></pre></td></tr></tbody></table></figure><p>这样也就无法输入到文本框了，所以我刚开始想了个妥协的方法，就是当没加载评论框时弹出提示说没有加载，需要手动滚到下方进行加载，这也是第一代方案，草草了事了~</p><h4 id="不完美实现方案"><a href="#不完美实现方案" class="headerlink" title="不完美实现方案"></a>不完美实现方案</h4><p>第二天起床，我想了一下，他没加载评论，那我就自己提前加载一下呗？于是我开始翻看Twikoo的文档，找到了以下文档：</p><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly90d2lrb28uanMub3JnL2Zyb250ZW5kLmh0bWwjJUU5JTgwJTlBJUU4JUJGJTg3LWNkbi0lRTUlQkMlOTUlRTUlODUlQTU" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">Twikoo文档#通过CDN引入前端页面</div><div class="tag-link-sitename">Twikoo.js.org</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><p>其中内容如下：</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/66220a3b6d784.png" alt="Twikoo通过CDN引入"></p><p>于是我写出了如下代码：</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 加载Twikoo库</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">loadTwikooLibrary</span>(<span class="params"></span>) {</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> {</span><br><span class="line">        <span class="keyword">var</span> script = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'script'</span>);</span><br><span class="line">        script.<span class="property">src</span> = <span class="string">'https://cdn.staticfile.org/twikoo/1.6.32/twikoo.all.min.js'</span>;</span><br><span class="line">        script.<span class="property">onload</span> = <span class="keyword">function</span>(<span class="params"></span>) {</span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">'Twikoo库加载成功'</span>);</span><br><span class="line">            <span class="title function_">resolve</span>();</span><br><span class="line">        };</span><br><span class="line">        script.<span class="property">onerror</span> = <span class="keyword">function</span>(<span class="params"></span>) {</span><br><span class="line">            <span class="title function_">reject</span>(<span class="string">'Twikoo库加载失败'</span>);</span><br><span class="line">        };</span><br><span class="line">        <span class="variable language_">document</span>.<span class="property">head</span>.<span class="title function_">appendChild</span>(script);</span><br><span class="line">    });</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 使用异步/await确保Twikoo库加载完成后执行操作</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">replySelect</span>(<span class="params"></span>) {</span><br><span class="line">    <span class="title function_">removeRightMenu</span>();</span><br><span class="line">    <span class="keyword">var</span> selectedText = <span class="variable language_">document</span>.<span class="title function_">getSelection</span>().<span class="title function_">toString</span>();</span><br><span class="line">    <span class="keyword">if</span> (selectedText.<span class="title function_">includes</span>(<span class="string">'\n'</span>)) {</span><br><span class="line">        selectedText = selectedText.<span class="title function_">split</span>(<span class="string">'\n'</span>)[<span class="number">0</span>];</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 检查评论框元素是否存在</span></span><br><span class="line">    <span class="keyword">var</span> commentBoxTest = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">".el-textarea__inner"</span>);</span><br><span class="line">    <span class="keyword">if</span> (!commentBoxTest) {</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">"加载评论中"</span>);</span><br><span class="line">        <span class="keyword">try</span> {</span><br><span class="line">            <span class="comment">// 等待Twikoo库加载完成</span></span><br><span class="line">            <span class="keyword">await</span> <span class="title function_">loadTwikooLibrary</span>();</span><br><span class="line">            <span class="comment">// 初始化Twikoo</span></span><br><span class="line">            twikoo.<span class="title function_">init</span>({</span><br><span class="line">                <span class="attr">envId</span>: <span class="string">'ddddddddddddd地址'</span>,</span><br><span class="line">                <span class="attr">el</span>: <span class="string">'#post-comment'</span>,</span><br><span class="line">            });</span><br><span class="line">        } <span class="keyword">catch</span> (error) {</span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">error</span>(error);</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> commentBox = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">".el-textarea__inner"</span>);</span><br><span class="line">    commentBox.<span class="property">value</span> = <span class="string">`&gt; <span class="subst">${selectedText}</span>\n\n`</span>;</span><br><span class="line">    commentBox.<span class="title function_">focus</span>();</span><br><span class="line">    <span class="keyword">var</span> replySelectMessage = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line">    replySelectMessage.<span class="property">textContent</span> = <span class="string">'不要删除空行显示效果更佳哦！'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">position</span> = <span class="string">'fixed'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">top</span> = <span class="string">'50%'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">left</span> = <span class="string">'50%'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">transform</span> = <span class="string">'translate(-50%, -50%)'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">backgroundColor</span> = <span class="string">'rgba(0, 0, 0, 0.7)'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">color</span> = <span class="string">'#fff'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">padding</span> = <span class="string">'10px 20px'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">borderRadius</span> = <span class="string">'5px'</span>;</span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">zIndex</span> = <span class="string">'9999'</span>;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(replySelectMessage);</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 2秒后移除提示消息</span></span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>){</span><br><span class="line">        <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(replySelectMessage);</span><br><span class="line">    }, <span class="number">2000</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 使用replySelect函数</span></span><br><span class="line">rm.<span class="property">replySelect</span> = replySelect;</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>这个方法解决了评论区没有加载的问题，但是因为他的评论区是只引入了一个twikoo，而我的评论区是双评论（其实屁用没有，不过当摆设倒是很高大上），导致他的样式和主题加载出来的有些不同，这里我没有记录截图，现在回退回去也有点麻烦，所以我就放一张正常的，解释一下哪里样式有问题：</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/66220b9d0316d.png" alt="红色部分为直接加载缺失的部分"></p><p>所以这个方法实现的也不是很完美，感觉怪郁闷的，因为本人为中度强迫症患者，只要我能解决的我会去解决，解决不了的我宁愿给他删掉。。。所以，我想出了最后的一种方案：弹窗法。</p><h4 id="完美-可能-实现方案"><a href="#完美-可能-实现方案" class="headerlink" title="完美(可能)实现方案"></a>完美(可能)实现方案</h4><p>经过了半天的思考，我在想，为什么我会被说说的评价局限住呢？我可以参考一下番茄小说，每段话后面有个按钮，点击后弹窗，那我也可以这么实现吧？再就是，我选中文字回复后，会跳转到页面底部的话，就算完美实现了，读者也需要重新跳过去才能继续阅读文章，这很大的影响了读者阅读体验，那我为什么不能原地弹窗，弹出之后不动页面，让读者评论完成后继续看呢？这样我也不需要考虑多评论了，因为这个没有什么主题自带的模板格式，完全是我自己造的，想怎么来怎么来！于是我开始使用JS实现这些功能，为了更加美观直接好理解，我将每个部分的内容封装成了函数：</p><h5 id="JS功能实现"><a href="#JS功能实现" class="headerlink" title="JS功能实现"></a>JS功能实现</h5><p>首先，加载twikoo的库：</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 加载Twikoo库</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">loadTwikooLibrary</span>(<span class="params"></span>) {</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> {</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable language_">window</span>.<span class="property">twikoo</span>) {</span><br><span class="line">            <span class="comment">// 如果 Twikoo 库已经加载过，则直接返回成功的 Promise</span></span><br><span class="line">            <span class="title function_">resolve</span>();</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        }</span><br><span class="line"></span><br><span class="line">        <span class="keyword">const</span> script = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'script'</span>);</span><br><span class="line">        script.<span class="property">src</span> = <span class="string">'https://cdn.staticfile.org/twikoo/1.6.31/twikoo.all.min.js'</span>;</span><br><span class="line">        script.<span class="property">onload</span> = <span class="function">() =&gt;</span> {</span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">'Twikoo库加载成功'</span>);</span><br><span class="line">            <span class="title function_">resolve</span>();</span><br><span class="line">        };</span><br><span class="line">        script.<span class="property">onerror</span> = <span class="function">() =&gt;</span> {</span><br><span class="line">            <span class="title function_">reject</span>(<span class="keyword">new</span> <span class="title class_">Error</span>(<span class="string">'Twikoo库加载失败'</span>));</span><br><span class="line">        };</span><br><span class="line">        <span class="variable language_">document</span>.<span class="property">head</span>.<span class="title function_">appendChild</span>(script);</span><br><span class="line">    });</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>这里我解释一下，这段代码会动态加载Twikoo库。返回一个 Promise，用于处理后续的异步操作。首先，它检查窗口对象 <code>window</code> 上是否已经有 <code>twikoo</code> 属性，即 Twikoo 库是否已经加载过。如果已经加载过，比如你提前已经回复过一次或者已经翻到下面加载成功过主评论区，它直接返回一个成功的 Promise。否则，它创建一个 <code>&lt;script&gt;</code> 元素，并将其 <code>src</code> 属性设置为 Twikoo 库的 URL。这会让网页加载 Twikoo 库文件。当库加载成功后，会在控制台中打印 “Twikoo库加载成功”，并返回Promise；如果加载失败，会 reject Promise 并返回错误信息。最后，将 <code>&lt;script&gt;</code> 元素添加到 <code>&lt;head&gt;</code> 部分中，开始加载 Twikoo 库（听不懂没关系，直接抄代码就行）。</p><p>下面我们开始创建弹窗，我想创建一个后面是遮罩层，前台一个框的弹窗，于是先创建遮罩层，再创建弹窗，分别写出以下函数：</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建遮罩层</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">createOverlay</span>(<span class="params"></span>) {</span><br><span class="line">    <span class="keyword">const</span> overlay = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line">    overlay.<span class="property">id</span> = <span class="string">'overlay'</span>;</span><br><span class="line">    overlay.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">'overlay'</span>); <span class="comment">// 添加 CSS 类</span></span><br><span class="line">    <span class="comment">// 添加点击监听器以关闭弹窗</span></span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">'click'</span>, handleClickOutsidePopup);</span><br><span class="line">    <span class="keyword">return</span> overlay;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建弹窗</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">createPopup</span>(<span class="params"></span>) {</span><br><span class="line">    <span class="keyword">const</span> popup = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line">    popup.<span class="property">id</span> = <span class="string">'popup'</span>;</span><br><span class="line">    popup.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">'popup'</span>); <span class="comment">// 添加 CSS 类</span></span><br><span class="line">    <span class="keyword">return</span> popup;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>创建了弹窗，我们还需要关闭弹窗，要不然下次就用不了了，于是我们再写一个关闭遮罩层的代码：</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 关闭弹窗并移除遮罩层</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">closePopup</span>(<span class="params">popup, overlay</span>) {</span><br><span class="line">    <span class="comment">// 隐藏遮罩层和弹窗的动画</span></span><br><span class="line">    overlay.<span class="property">style</span>.<span class="property">opacity</span> = <span class="number">0</span>;</span><br><span class="line">    popup.<span class="property">style</span>.<span class="property">opacity</span> = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 在动画结束后移除元素</span></span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> {</span><br><span class="line">        <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(popup);</span><br><span class="line">        <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(overlay);</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">removeEventListener</span>(<span class="string">'click'</span>, handleClickOutsidePopup);</span><br><span class="line">    }, <span class="number">300</span>); <span class="comment">// 动画持续时间与 transition 持续时间一致</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 点击弹窗外部关闭弹窗</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">handleClickOutsidePopup</span>(<span class="params">event</span>) {</span><br><span class="line">    <span class="keyword">const</span> popup = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'popup'</span>);</span><br><span class="line">    <span class="keyword">if</span> (popup &amp;&amp; !popup.<span class="title function_">contains</span>(event.<span class="property">target</span>)) {</span><br><span class="line">        <span class="title function_">closePopup</span>(popup, <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'overlay'</span>));</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>这里我创建了一个事件，点击弹窗以外的空白位置关闭弹窗（可能是人之常情？总喜欢点别的地方来关闭它，至少我是这样），本来是有个按钮的，但是嫌弃他太丑了给删掉了，后面看看能不能加上一个更加美观的。</p><p>然后我将之前的提示消息弹窗的内容也封装成了函数（反正封了这么多不差这一个），方便其他位置直接调用即可，因为代码量还是不小的，有点占地方。</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 通用函数：显示提示消息</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">showMessage</span>(<span class="params">message, duration = <span class="number">2000</span></span>) {</span><br><span class="line">    <span class="comment">// 创建提示消息元素</span></span><br><span class="line">    <span class="keyword">const</span> replySelectMessage = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line">    replySelectMessage.<span class="property">innerHTML</span> = message;</span><br><span class="line">    replySelectMessage.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">'pop-message'</span>); <span class="comment">// 添加 CSS 类</span></span><br><span class="line">    <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(replySelectMessage);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 设置初始透明度为0</span></span><br><span class="line">    replySelectMessage.<span class="property">style</span>.<span class="property">opacity</span> = <span class="string">'0'</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 使用 setTimeout 设置动画显示提示消息</span></span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> {</span><br><span class="line">        replySelectMessage.<span class="property">style</span>.<span class="property">opacity</span> = <span class="string">'1'</span>;</span><br><span class="line">    }, <span class="number">10</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 定义移除提示消息的函数</span></span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">removeMessage</span>(<span class="params"></span>) {</span><br><span class="line">        <span class="comment">// 将透明度设置为0，使其隐藏</span></span><br><span class="line">        replySelectMessage.<span class="property">style</span>.<span class="property">opacity</span> = <span class="string">'0'</span>;</span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 等待隐藏动画完成后移除元素</span></span><br><span class="line">        <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> {</span><br><span class="line">            <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(replySelectMessage);</span><br><span class="line">        }, <span class="number">500</span>); <span class="comment">// 动画持续时间</span></span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 根据指定的持续时间设置定时器来移除提示消息</span></span><br><span class="line">    <span class="built_in">setTimeout</span>(removeMessage, duration);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>这个函数接受两个参数，内容和时间（默认两秒），函数都封装完了，需要开始组装了！把面向对象贯彻到底，继续封装函数！</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 显示带评论的弹窗</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">showPopupWithComments</span>(<span class="params">envId, commentElementId</span>) {</span><br><span class="line">    <span class="comment">// 创建遮罩层</span></span><br><span class="line">    <span class="keyword">const</span> overlay = <span class="title function_">createOverlay</span>();</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 创建弹窗</span></span><br><span class="line">    <span class="keyword">const</span> popup = <span class="title function_">createPopup</span>();</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 添加评论部分</span></span><br><span class="line">    <span class="keyword">const</span> commentSection = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line">    commentSection.<span class="property">id</span> = commentElementId;</span><br><span class="line">    popup.<span class="title function_">appendChild</span>(commentSection);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 将弹窗和遮罩添加到文档中</span></span><br><span class="line">    <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(overlay);</span><br><span class="line">    <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(popup);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 初始化 Twikoo</span></span><br><span class="line">    twikoo.<span class="title function_">init</span>({ envId, <span class="attr">el</span>: <span class="string">`#<span class="subst">${commentElementId}</span>`</span> });</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 显示提示消息并在 2 秒后移除</span></span><br><span class="line">    <span class="title function_">showMessage</span>(<span class="string">'点击弹窗外任意部分即可退出'</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 显示遮罩层和弹窗的动画</span></span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> {</span><br><span class="line">        overlay.<span class="property">style</span>.<span class="property">opacity</span> = <span class="number">1</span>;</span><br><span class="line">        popup.<span class="property">style</span>.<span class="property">opacity</span> = <span class="number">1</span>;</span><br><span class="line">    }, <span class="number">0</span>);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>我的注释应该已经够详细了，所以就不解释了，这个就是我们显示待评论的弹窗，然后我们将其在回复按钮的相应事件中调用：</p><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 使用异步/await确保Twikoo库加载完成后执行操作</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">replySelect</span>(<span class="params"></span>) {</span><br><span class="line">    <span class="title function_">removeRightMenu</span>();</span><br><span class="line">    <span class="keyword">var</span> selectedText = <span class="variable language_">document</span>.<span class="title function_">getSelection</span>().<span class="title function_">toString</span>().<span class="title function_">trim</span>();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (selectedText.<span class="title function_">includes</span>(<span class="string">'\n'</span>)) {</span><br><span class="line">        selectedText = selectedText.<span class="title function_">split</span>(<span class="string">'\n'</span>)[<span class="number">0</span>].<span class="title function_">trim</span>();</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> {</span><br><span class="line">        <span class="comment">// 等待Twikoo库加载完成</span></span><br><span class="line">        <span class="keyword">await</span> <span class="title function_">loadTwikooLibrary</span>();</span><br><span class="line">        <span class="comment">// 显示带评论的弹窗</span></span><br><span class="line">        <span class="title function_">showPopupWithComments</span>(<span class="string">'你的twikoo地址或者按照官方的腾讯环境ID'</span>, <span class="string">'comment-section'</span>);</span><br><span class="line">    } <span class="keyword">catch</span> (error) {</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">error</span>(error);</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> commentBox = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">"#popup .el-textarea__inner"</span>);</span><br><span class="line">    commentBox.<span class="property">value</span> = <span class="string">`&gt; <span class="subst">${selectedText}</span>\n\n`</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 将 replySelect 函数绑定到特定事件或对象</span></span><br><span class="line">rm.<span class="property">replySelect</span> = replySelect;</span><br></pre></td></tr></tbody></table></figure><p>上面需要改你的Twikoo的地址，在倒数第二行，我修改了获取文本框的CSS路径，防止匹配到主评论区了，最后将将 replySelect 函数绑定到事件上。</p><h5 id="CSS添加"><a href="#CSS添加" class="headerlink" title="CSS添加"></a>CSS添加</h5><p>到这里还没完，因为我们没有指定任何样式，下面是所有的CSS内容，这个比较简单我就不解释啦！直接复制到你的自定义CSS文件中即可！</p><div class="note note-info"><div class="note-header"><i class="note-icon fa-regular fa-circle-check"></i> <span class="note-title">更新记录</span></div><div class="note-content"><p>下方代码2024-04-20更新：第六十四行，由于刷新按钮为Twikoo官方内部封装，为方便后续升级不想对其修改，于是将其隐藏防止误触</p></div></div><figure class="highlight css"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 设置评论弹窗的一些参数 */</span></span><br><span class="line"><span class="comment">/* 遮罩层样式 */</span></span><br><span class="line"><span class="selector-class">.overlay</span> {</span><br><span class="line">    <span class="attribute">position</span>: fixed;</span><br><span class="line">    <span class="attribute">top</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">left</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.7</span>);</span><br><span class="line">    <span class="attribute">z-index</span>: <span class="number">999</span>;</span><br><span class="line">    <span class="attribute">opacity</span>: <span class="number">0</span>; <span class="comment">/* 初始透明度为 0 */</span></span><br><span class="line">    <span class="attribute">transition</span>: opacity <span class="number">0.3s</span>; <span class="comment">/* 过渡效果，持续时间为 0.3 秒 */</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-attr">[data-theme=dark]</span> <span class="selector-class">.overlay</span> {</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0.7</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 弹窗样式 */</span></span><br><span class="line"><span class="selector-class">.popup</span> {</span><br><span class="line">    <span class="attribute">position</span>: fixed;</span><br><span class="line">    <span class="attribute">top</span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">left</span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">translate</span>(-<span class="number">50%</span>, -<span class="number">50%</span>);</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.7</span>);</span><br><span class="line">    <span class="attribute">padding</span>: <span class="number">20px</span>;</span><br><span class="line">    <span class="attribute">border</span>: <span class="number">1px</span> solid <span class="number">#ccc</span>;</span><br><span class="line">    <span class="attribute">z-index</span>: <span class="number">1000</span>;</span><br><span class="line">    <span class="attribute">max-height</span>: <span class="number">80%</span>;</span><br><span class="line">    <span class="attribute">overflow-y</span>: auto;</span><br><span class="line">    <span class="attribute">border-radius</span>: <span class="number">20px</span>;</span><br><span class="line">    <span class="attribute">opacity</span>: <span class="number">0</span>; <span class="comment">/* 初始透明度为 0 */</span></span><br><span class="line">    <span class="attribute">transition</span>: opacity <span class="number">0.3s</span>; <span class="comment">/* 过渡效果，持续时间为 0.3 秒 */</span></span><br><span class="line">    <span class="attribute">scrollbar-width</span>: none; <span class="comment">/* 隐藏滚动条（适用于 Firefox） */</span></span><br><span class="line">    -ms-<span class="attribute">overflow</span>-style: none; <span class="comment">/* 隐藏滚动条（适用于 IE 和 Edge） */</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-attr">[data-theme=dark]</span> <span class="selector-class">.popup</span> {</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">44</span>, <span class="number">44</span>, <span class="number">44</span>, <span class="number">0.7</span>);</span><br><span class="line">    <span class="attribute">border</span>: <span class="number">1px</span> solid <span class="number">#666</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 通用弹窗消息样式 */</span></span><br><span class="line"><span class="selector-class">.pop-message</span> {</span><br><span class="line">    <span class="attribute">position</span>: fixed;</span><br><span class="line">    <span class="attribute">top</span>: <span class="number">70px</span>; <span class="comment">/* 距离顶部10px */</span></span><br><span class="line">    <span class="attribute">right</span>: <span class="number">10px</span>; <span class="comment">/* 距离右侧10px */</span></span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.7</span>);</span><br><span class="line">    <span class="attribute">color</span>: <span class="number">#000000</span>;</span><br><span class="line">    <span class="attribute">padding</span>: <span class="number">20px</span> <span class="number">30px</span>;</span><br><span class="line">    <span class="attribute">border-radius</span>: <span class="number">10px</span>;</span><br><span class="line">    <span class="attribute">z-index</span>: <span class="number">9999</span>;</span><br><span class="line">    <span class="attribute">border</span>: <span class="number">1px</span> solid <span class="number">#000000</span>; <span class="comment">/* 添加边框，1px宽度，灰色 */</span></span><br><span class="line">    <span class="attribute">opacity</span>: <span class="number">0</span>; <span class="comment">/* 初始状态设置为透明 */</span></span><br><span class="line">    <span class="attribute">transition</span>: opacity <span class="number">1.0s</span> ease-in-out; <span class="comment">/* 添加渐变动画 */</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-attr">[data-theme=dark]</span> <span class="selector-class">.pop-message</span> {</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">44</span>, <span class="number">44</span>, <span class="number">44</span>, <span class="number">0.7</span>);</span><br><span class="line">    <span class="attribute">color</span>: <span class="number">#fff</span>;</span><br><span class="line">    <span class="attribute">border</span>: <span class="number">1px</span> solid <span class="number">#ffffff</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 由于twikoo内部函数不宜修改，去掉刷新按钮 */</span></span><br><span class="line"><span class="selector-id">#popup</span> <span class="selector-id">#twikoo</span> <span class="selector-class">.tk-comments</span> <span class="selector-class">.tk-comments-container</span> <span class="selector-class">.tk-comments-title</span> &gt; <span class="selector-tag">span</span><span class="selector-pseudo">:nth-child</span>(<span class="number">2</span>) &gt; <span class="selector-tag">span</span><span class="selector-pseudo">:nth-child</span>(<span class="number">1</span>) {</span><br><span class="line">	<span class="attribute">display</span>: none;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h2 id="展示效果"><a href="#展示效果" class="headerlink" title="展示效果"></a>展示效果</h2><p>最终的效果我也很满意，下面是一些效果图：</p><div class="tabs"><div class="nav-tabs"><button type="button" class="tab active">白天模式</button><button type="button" class="tab">夜间模式</button><button type="button" class="tab">手机模式</button></div><div class="tab-contents"><div class="tab-item-content active"><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/66221498b38f3.png" alt="白天模式适配"></p></div><div class="tab-item-content"><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/66221777d9d7f.png" alt="夜间模式适配"></p></div><div class="tab-item-content"><p>其实后面想想，手机也没有右键菜单啊？算了不管了，就当是分辨率适配啦</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/6622182aea964.png" alt="窄屏模式适配"></p></div></div><div class="tab-to-top"><button type="button" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>这次魔改是我最近比较大的一次尝试，作为入场一个月的小白，慢慢成长，我也能感受到我的收获，后面我会继续学习，实现更多的功能！</p><p>完结撒花！</p><h2 id="每日一图"><a href="#每日一图" class="headerlink" title="每日一图"></a>每日一图</h2><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/19/6622194c9d110.png" alt="非原图，清晰度可能不高"></p></article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>twikoo仿段落评论，实现快速评论功能</h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="https://blog.liushen.fun/posts/73765344/">https://blog.liushen.fun/posts/73765344/</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info" style="position:relative;z-index:3"><div class="post-copyright-a" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>作者</h><div class="post-copyright-cc-info"><h>LiuShen</h></div></div><div class="post-copyright-c" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>发布于</h><div class="post-copyright-cc-info"><h>2024-04-20</h></div></div><div class="post-copyright-u" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>更新于</h><div class="post-copyright-cc-info"><h>2024-04-19</h></div></div><div class="post-copyright-c" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>许可协议</h><div class="post-copyright-cc-info"><a rel="noopener" target="_blank" title=" CC BY 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/?ref=chooser-v1">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E5%8A%9F%E8%83%BD/">功能</a><a class="post-meta__tags" href="/tags/CSS/">CSS</a><a class="post-meta__tags" href="/tags/Hexo/">Hexo</a><a class="post-meta__tags" href="/tags/twikoo/">twikoo</a><a class="post-meta__tags" href="/tags/JavaScript/">JavaScript</a></div><div class="post-share"><div class="social-share" data-image="https://p.liiiu.cn/i/2024/04/19/6621c4a8c099b.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/butterfly-extsrc@1.1.4/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://jsd.liiiu.cn/npm/butterfly-extsrc@1.1.4/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i>来😍鼠标过来一点~</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/config/img/wechat.png" target="_blank"><img class="post-qr-code-img" src="" data-lazy-src="/config/img/wechat.png" alt="微信"></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/config/img/wechat.png" target="_blank"><img class="post-qr-code-img" src="" data-lazy-src="/config/img/wechat.png" alt="支付宝"></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><a class="prev-post pull-left" href="/posts/c4a2ff35/" title="怎么从PPT中提取出所有的文字内容"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/18/6620768f55c9a.png" onerror='onerror=null,src="/img/404.jpg"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">怎么从PPT中提取出所有的文字内容</div></div></a><a class="next-post pull-right" href="/posts/9efc1657/" title="安全跳转页面·重制版"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/20/6623e50e7b7d2.png" onerror='onerror=null,src="/img/404.jpg"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">安全跳转页面·重制版</div></div></a></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a href="/posts/b9d10ed/" title="魔改笔记六：twikoo及导航栏美化"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2024/05/07/6639d988af1b3.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-05-07</div><div class="title">魔改笔记六：twikoo及导航栏美化</div></div></a><a href="/posts/51728b12/" title="魔改笔记一：简单特效添加"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2024/04/10/6616120325702.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-02-23</div><div class="title">魔改笔记一：简单特效添加</div></div></a><a href="/posts/a64defb4/" title="魔改笔记七：分类条及外链卡片"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2024/08/10/66b74df1ab511.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-08-10</div><div class="title">魔改笔记七：分类条及外链卡片</div></div></a></div></div><hr class="custom-hr"><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="artalk-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info is-center"><div class="author-info-detail"><p class="author-info-hello">👋 欢迎光临！</p><p class="author-info-desc">你们好呀！我是站长LiuShen！一个快乐，积极，热爱生活的孩纸！😜😜😜</p></div><div class="avatar-img"><img class="mood-icon" src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/14/67d301461a24a.webp" alt="🤤" onerror='this.onerror=null,this.src="/img/friend_404.gif"'><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/13/67d2fc82d329c.webp" onerror='this.onerror=null,this.src="/img/friend_404.gif"' alt="avatar"></div><div class="author-info-name">LiuShen</div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">72</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">98</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/willow-god"><i class="fab fa-github"></i><span>Follow Me 🛫</span></a><div class="card-info-social-icons"><a class="social-icon" href="mailto:01@liushen.fun" target="_blank" title="Email"><i class="fa-solid fa-envelope"></i></a><a class="social-icon" href="http://wpa.qq.com/msgrd?v=3&amp;uin=3162475700&amp;site=qq&amp;menu=yes" target="_blank" title="QQ：3162475700"><i class="fa-brands fa-qq"></i></a><a class="social-icon" href="https://wakatime.com/@LiuShen" target="_blank" title="Wakatime"><i class="fa-solid fa-chart-column"></i></a><a class="social-icon" href="https://blog.liushen.fun/atom.xml" target="_blank" title="rss地址"><i class="fa-solid fa-rss"></i></a></div></div><div class="card-widget" id="card-poem"><div id="poem_sentence"></div><div id="poem_info"><div id="poem_dynasty"></div><div id="poem_author"></div></div></div><script src="/js/jinrishici.js" charset="utf-8"></script><script>jinrishici.load((function(e){var n=document.querySelector("#poem_sentence"),t=document.querySelector("#poem_author"),o=document.querySelector("#poem_dynasty"),r=e.data.content;r=r.substr(0,r.length-1),n.innerHTML=r,o.innerHTML=e.data.origin.dynasty,t.innerHTML=e.data.origin.author+"《"+e.data.origin.title+"》"}))</script><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content"><p><strong>博客架构概览：</strong><br>⚙️框架核心：Hexo<br>🕹️界面设计：Butterfly<br>🔮安全保障：长亭雷池<br>🔩管理工具：宝塔面板，1Panel<br>🎰服务器支持：阿里云，腾讯云<br>🎲CDN加速：多吉云，CloudFlare<br><strong>快捷跳转地址：</strong><br>🧩个人相册：<a target="_blank" rel="noopener" href="https://xc.liushen.fun">xc.liushen.fun</a><br>🤖个人导航：<a target="_blank" rel="noopener" href="https://www.liushen.fun">www.liushen.fun</a><br></p><img src="" data-lazy-src="/config/img/notice.gif" alt="可爱捏" title="可爱捏" style="width:100%;border-radius:10px"></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A2%8E%E7%A2%8E%E5%BF%B5"><span class="toc-text">碎碎念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E5%AE%B9%E7%AE%80%E8%BF%B0"><span class="toc-text">内容简述</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E5%8A%9F%E8%83%BD"><span class="toc-text">实现功能</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E6%8C%89%E9%92%AE"><span class="toc-text">添加按钮</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E5%87%BD%E6%95%B0"><span class="toc-text">实现函数</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%A6%A5%E5%8D%8F%E6%96%B9%E6%A1%88"><span class="toc-text">妥协方案</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%8D%E5%AE%8C%E7%BE%8E%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%A1%88"><span class="toc-text">不完美实现方案</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%8C%E7%BE%8E-%E5%8F%AF%E8%83%BD-%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%A1%88"><span class="toc-text">完美(可能)实现方案</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#JS%E5%8A%9F%E8%83%BD%E5%AE%9E%E7%8E%B0"><span class="toc-text">JS功能实现</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#CSS%E6%B7%BB%E5%8A%A0"><span class="toc-text">CSS添加</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B1%95%E7%A4%BA%E6%95%88%E6%9E%9C"><span class="toc-text">展示效果</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-text">总结</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%AF%8F%E6%97%A5%E4%B8%80%E5%9B%BE"><span class="toc-text">每日一图</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/7915ee6b/" title="数据库可视化WEB工具对比"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/05/25/6832cc105bc41.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="数据库可视化WEB工具对比"></a><div class="content"><a class="title" href="/posts/7915ee6b/" title="数据库可视化WEB工具对比">数据库可视化WEB工具对比</a><time datetime="2025-05-25T10:01:21.000Z" title="更新于 2025-05-25 18:01:21">2025-05-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/40702a0d/" title="本地实现HEXO文章AI摘要"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/05/06/6819cd4532457.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="本地实现HEXO文章AI摘要"></a><div class="content"><a class="title" href="/posts/40702a0d/" title="本地实现HEXO文章AI摘要">本地实现HEXO文章AI摘要</a><time datetime="2025-05-06T16:01:21.000Z" title="更新于 2025-05-07 00:01:21">2025-05-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5f71a4b1/" title="耗子面板和DPanel简单体验"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/04/27/680dc7916ef34.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="耗子面板和DPanel简单体验"></a><div class="content"><a class="title" href="/posts/5f71a4b1/" title="耗子面板和DPanel简单体验">耗子面板和DPanel简单体验</a><time datetime="2025-04-28T14:48:21.000Z" title="更新于 2025-04-28 22:48:21">2025-04-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/caee2d9f/" title="美化你的RSS订阅地址"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/04/18/68024a618942b.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="美化你的RSS订阅地址"></a><div class="content"><a class="title" href="/posts/caee2d9f/" title="美化你的RSS订阅地址">美化你的RSS订阅地址</a><time datetime="2025-04-18T12:48:21.000Z" title="更新于 2025-04-18 20:48:21">2025-04-18</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap" style="background:0 0"><div id="footer_icons"><div><a class="icon_link" rel="noopener external nofollow" href="https://www.liushen.fun/" title="导航站点" target="_blank"><i class="fa-solid fa-compass"></i></a><a class="icon_link" rel="noopener external nofollow" href="https://admin.qidian.qq.com/static_proxy/b2b-qq/wpa-link/index.html#/person?uin=3162475700" title="联系QQ" target="_blank"><i class="fa-brands fa-qq"></i></a><a class="icon_link" rel="noopener external nofollow" href="https://github.com/willow-god" title="我的github主页" target="_blank"><i class="fa-brands fa-github"></i></a><a class="icon_link" rel="noopener external nofollow" href="mailto:01@liushen.fun" title="发送邮件至博主邮箱" target="_blank"><i class="fa-solid fa-envelope"></i></a></div><div class="footer_logo_container" onclick="btf.scrollToDest(0,500)" title="返回顶部"><img class="footer_logo" src="" data-lazy-src="/img/footer.gif"></div><div><a class="icon_link" rel="noopener external nofollow" href="https://wakatime.com/@LiuShen" title="Wikitime" target="_blank"><i class="fa-solid fa-clock"></i></a><a class="icon_link" rel="noopener external nofollow" href="https://gitlab.com/" title="gitlab" target="_blank"><i class="fa-brands fa-gitlab"></i></a><a class="icon_link" href="/shuoshuo/" title="日常说说" data-pjax-state="data-pjax-state"><i class="fa-solid fa-file-pen"></i></a><a class="icon_link" href="/comment/" title="留言板" data-pjax-state="data-pjax-state"><i class="fa-solid fa-comment"></i></a></div></div><div id="footer_content"><div class="footer-group"><h3 class="footer-title">关于本站</h3><div class="footer-links"><a class="footer-item" target="_blank" href="https://www.liushen.fun/">导航站点</a><a class="footer-item" href="/shuoshuo/">日常说说</a><a class="footer-item" target="_blank" href="https://um.liushen.fun/share/bIEnQp0xnMxD8c9V/blog.liushen.fun">访客信息</a><a class="footer-item" target="_blank" href="https://mm.liushen.fun/">提笔摘星</a><a class="footer-item" target="_blank" href="https://status.liushen.fun/">在线状态</a><a class="footer-item" href="/subscribe/">订阅本站</a></div></div><div class="footer-group"><h3 class="footer-title">加入组织</h3><div class="footer-links"><a class="footer-item" target="_blank" href="https://www.boyouquan.com/home">博友圈</a><a class="footer-item" target="_blank" href="https://github.com/timqian/chinese-independent-blogs">中博列表</a><a class="footer-item" target="_blank" href="https://blogwe.com/">博客我们</a><a class="footer-item" target="_blank" href="https://storeweb.cn/">个性商店</a><a class="footer-item" target="_blank" href="https://bf.zzxworld.com/">发现博客</a><a class="footer-item" target="_blank" href="https://ourblo.gs/">OurBlogs</a></div></div><div class="footer-group"><h3 class="footer-title">文章整理</h3><div class="footer-links"><a class="footer-item" href="/categories/website/">博客管理</a><a class="footer-item" href="/categories/learning/">学习资料</a><a class="footer-item" href="/categories/daily-share/">日常分享</a><a class="footer-item" href="/archives/">时光卷轴</a><a class="footer-item" href="/charts/">文章通览</a><a class="footer-item" href="/categories/">查看全部</a></div></div><div class="footer-group"><h3 class="footer-title">文章标签</h3><div class="footer-links"><a class="footer-item" href="/tags/JavaScript/">JS知识</a><a class="footer-item" href="/tags/Hexo/">本站框架</a><a class="footer-item" href="/tags/机器学习/">机器学习</a><a class="footer-item" href="/tags/日记/">个人日记</a><a class="footer-item" href="/tags/CSS/">CSS知识</a><a class="footer-item" href="/tags/">查看全部</a></div></div><div class="footer-group"><h3 class="footer-title">自建工具</h3><div class="footer-links"><a class="footer-item" target="_blank" rel="noopener" href="https://chat.liushen.fun/">清羽AI</a><a class="footer-item" target="_blank" rel="noopener" href="https://hot.liushen.fun/">今日热榜</a><a class="footer-item" target="_blank" rel="noopener" href="https://cover.qyliu.top/">封面设计</a><a class="footer-item" target="_blank" rel="noopener" href="https://icon.qyliu.top/">万变图标</a><a class="footer-item" target="_blank" rel="noopener" href="https://tmail.qyliu.top/">临时邮箱</a><a class="footer-item" target="_blank" rel="noopener" href="https://share.liushen.fun/">内容中转</a></div></div><div class="footer-group" id="friend-links-in-footer"><h3 class="footer-title">友链<button title="换一批" href="javascript:;" onclick="liushen.randomLink()"><i class="fa-solid fa-rotate-right"></i></button></h3><div class="footer-links"><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试1</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试2</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试3</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试4</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试5</a><a class="footer-item" href="/link/" data-pjax-state="data-pjax-state">查看更多</a></div></div></div><div id="footer-bottom"><div class="footer-bottom-content"><div class="footer-bottom-left"><span class="copyright">©2021 - 2025 By <a target="_blank" rel="noopener" href="https://blog.liushen.fun/about/" title="点击访问&quot;LiuShen&quot;的主页" style="margin-left:5px">LiuShen</a></span><div><a class="footer-bottom-link" target="_blank" href="https://beian.miit.gov.cn/" rel="noopener external nofollow" title="工信部备案号">陕ICP备2024028531号-2</a><a class="footer-bottom-link" target="_blank" href="https://beian.mps.gov.cn/#/query/webSearch?code=61011602000637" rel="noopener external nofollow" title="公安备案号">陕公网安备61011602000637号</a></div></div><div class="footer-bottom-right"><div id="runtime" title="本站运行时间">本站已苟活：0 天 0 时 0 分 0 秒</div><div><a class="footer-bottom-link" target="_blank" href="https://www.dogecloud.com/?iuid=9173" rel="noopener external nofollow" title="本站通过多吉云CDN提供站点加速">多吉云CDN</a><a class="footer-bottom-link" target="_blank" href="https://hexo.io/zh-cn/" rel="noopener external nofollow" title="本站使用Hexo架构搭建而成">Hexo静态框架</a><a class="footer-bottom-link" target="_blank" href="https://butterfly.js.org/" rel="noopener external nofollow" title="本站主题由Butterfly主题魔改而成">LiuShen主题</a></div></div></div></div></div><script>window.liushen||(window.liushen={saveData:(e,n)=>{localStorage.setItem(e,JSON.stringify({time:Date.now(),data:n}))},loadData:(e,n)=>{let t=JSON.parse(localStorage.getItem(e));if(t){let e=Date.now()-t.time;if(e>=0&&e<6e4*n)return t.data}return null},runtime:()=>{const e=e=>e>9?e:"0"+e,n=new Date("2021/12/12 01:27:36").getTime(),t=Date.now();let i=Math.round((t-n)/1e3),o="本站已苟活：";i>=86400&&(o+=`${e(Math.floor(i/86400))} 天 `,i%=86400),i>=3600&&(o+=`${e(Math.floor(i/3600))} 时 `,i%=3600),i>=60&&(o+=`${e(Math.floor(i/60))} 分 `,i%=60),o+=`${e(i)} 秒`;const l=document.getElementById("runtime");l&&(l.innerHTML=o),setTimeout(window.liushen.runtime,1e3)},randomLink:()=>{let e=window.liushen.loadData("links",30);if(e){let n=document.querySelectorAll("#friend-links-in-footer .footer-item");if(!n.length)return;for(let t=0;t<n.length;t++){let i=Math.floor(Math.random()*e.length);n[t].innerText=e[i].name,n[t].href=e[i].link,e.splice(i,1)}}else fetch("/flink_count.json").then((e=>e.json())).then((e=>{window.liushen.saveData("links",e.link_list),window.liushen.randomLink()}))}}),window.liushen.randomLink(),document.addEventListener("DOMContentLoaded",window.liushen.randomLink),window.liushen.runtime()</script></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="translateLink" type="button" title="简繁转换" style="width:35px">繁</button><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i><span class="rightside-text">阅读模式</span></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fa-regular fa-star-half-stroke"></i><span class="rightside-text">亮暗切换</span></button><button id="cat" onclick="toggleLive2dVisibility()" title="小猫显隐"><i class="fa-solid fa-cat"></i><span class="rightside-text">小猫显隐</span></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fa-solid fa-arrows-left-right-to-line"></i><span class="rightside-text">侧栏显隐</span></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i><span class="rightside-text">更多设置</span></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i><span class="rightside-text">显示目录</span></button><button id="fullscreen" onclick="toggleFullScreen()" title="全屏切换"><i class="fa-solid fa-expand"></i><span class="rightside-text">全屏切换</span></button><a id="to_comment" href="#post-comment" title="前往评论"><i class="fas fa-comments"></i><span class="rightside-text">快速评论</span></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i><span class="rightside-text">回到顶部</span></button></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div><div class="rightMenu-item" id="menu-home"><i class="fa-solid fa-house"></i></div></div><div class="rightMenu-group rightMenu-line hide" id="menu-text"><a class="rightMenu-item" id="copy" href="javascript:rm.copySelect();"><i class="fa-solid fa-copy"></i><span>复制选中文字</span></a><a class="rightMenu-item" id="reply" href="javascript:rm.replySelect();"><i class="fa-regular fa-comment"></i><span>评论选中段落</span></a></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" href="/archives/"><i class="fa-solid fa-archive"></i><span>文章时间线</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="fa-solid fa-folder-open"></i><span>文章分大类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="fa-solid fa-tags"></i><span>文章小标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuNormal"><a class="rightMenu-item menu-link" id="menu-radompage" href="/comment/"><i class="fa-solid fa-shoe-prints"></i><span>随心留言板</span></a><div class="rightMenu-item" id="menu-translate"><i class="fa-solid fa-earth-asia"></i><span>繁简模式切换</span></div><div class="rightMenu-item" id="menu-live2dvisibility"><i class="fa-solid fa-cat"></i><span>小猫显示隐藏</span></div><div class="rightMenu-item" id="menu-print"><i class="fa-solid fa-print fa-fw"></i><span>打印整个页面</span></div><a class="rightMenu-item menu-link" id="statement" href="/statement/"><i class="fa-regular fa-copyright fa-fw"></i><span>网站声明</span></a></div></div><div id="rightmenu-mask"></div><div><script src="/js/others.js?v=5.0.0"></script><script src="/js/utils.js?v=5.0.0"></script><script src="/js/main.js?v=5.0.0"></script><script src="https://jsd.liiiu.cn/npm/echarts@5.5.1/dist/echarts.simple.min.js"></script><script src="/js/rightmenu.js?v=5.0.0"></script><script src="/js/jinrishici.js"></script><script src="/js/tw_cn.js?v=5.0.0"></script><script src="https://jsd.liiiu.cn/npm/@fancyapps/ui@5.0.36/dist/fancybox/fancybox.umd.min.js"></script><script src="https://jsd.liiiu.cn/npm/instant.page@5.2.0/instantpage.min.js" type="module"></script><script src="https://jsd.liiiu.cn/npm/vanilla-lazyload@19.1.3/dist/lazyload.iife.min.js"></script><div class="js-pjax"><script>(()=>{let t=null;const e=null,o="shuoshuo"===GLOBAL_CONFIG_SITE.pageType,a=()=>{t&&(t.destroy(),t=null)},n=e=>t&&t.setDarkMode("dark"===e),l=(l=document,i=location.pathname)=>{t=Artalk.init({el:l.querySelector("#artalk-wrap"),server:"https://atk.liushen.fun",site:"清羽飞扬",darkMode:"dark"===document.documentElement.getAttribute("data-theme"),...e,pageKey:i,imgUploader:function(t){let e="Bearer 28|q18njD3pLtHiFy9WidqQrREwqZzb8Zionr8WzilI",o="https://www.baiwulin.work/api/v1/upload",a=new Headers;a.set("Accept","application/json"),a.set("Authorization",e);let n=new FormData;n.append("file",t);const l=(t,e,o)=>fetch(t,{method:"POST",body:e,headers:o}).then((t=>t.json())).then((t=>t.data.links.url)).catch((t=>(console.error("Image upload failed:",t),null)));return l(o,n,a).then((t=>t||(console.warn("雾林图床接口失败，尝试替换为秋叶图床"),e="Bearer 11|lsReISlSS0dyhDzt35ovtfYefGbWSRW2vvntPXs7",o="https://imgse.koxiuqiu.cc/api/v1/upload",a.set("Authorization",e),l(o,n,a))))}}),"null"!==GLOBAL_CONFIG.lightbox&&(t.on("list-loaded",(()=>{t.ctx.get("list").getCommentNodes().forEach((t=>{const e=t.getRender().$content;btf.loadLightbox(e.querySelectorAll("img:not([atk-emoticon])"))}))})),o&&(window.shuoshuoComment.destroyArtalk=()=>{a(),l.children.length&&(l.innerHTML="",l.classList.add("no-comment"))}),btf.addGlobalFn("pjaxSendOnce",a,"destroyArtalk"),btf.addGlobalFn("themeChange",n,"artalk"))},i=async(t,e)=>{"object"==typeof Artalk||(await btf.getCSS("https://jsd.liiiu.cn/npm/artalk@2.9.1/dist/Artalk.min.css"),await btf.getScript("https://jsd.liiiu.cn/npm/artalk@2.9.1/dist/Artalk.min.js")),l(t,e)};o?window.shuoshuoComment={loadComment:i}:setTimeout(i,0)})()</script></div><script>window.newestComments={changeContent:e=>(""===e||(e=(e=(e=(e=(e=e.replace(/<img.*?src="(.*?)"?[^\>]+>/gi,"[图片]")).replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,"[链接]")).replace(/<pre><code>.*?<\/pre>/gi,"[代码]")).replace(/<code>.*?<\/code>/gi,"[代码]")).replace(/<[^>]+>/g,"")).length>150&&(e=e.substring(0,150)+"..."),e),generateHtml:(e,t)=>{let n="";if(e.length)for(let t=0;t<e.length;t++){if(n+='<div class="aside-list-item">',e[t].avatar){const a="data-lazy-src";n+=`<a href="${e[t].url}" class="thumbnail"><img ${a}="${e[t].avatar}" alt="${e[t].nick}"></a>`}n+=`<div class="content">\n        <a class="comment" href="${e[t].url}" title="${e[t].content}">${e[t].content}</a>\n        <div class="name"><span>${e[t].nick} / </span><time datetime="${e[t].date}">${btf.diffDate(e[t].date,!0)}</time></div>\n        </div></div>`}else n+="暂无评论";t.innerHTML=n,window.lazyLoadInstance&&window.lazyLoadInstance.update(),window.pjax&&window.pjax.refresh(t)},newestCommentInit:(e,t)=>{const n=document.querySelector("#card-newest-comments .aside-list");if(n){const a=btf.saveToLocal.get(e);a?newestComments.generateHtml(JSON.parse(a),n):t(n)}},run:(e,t)=>{newestComments.newestCommentInit(e,t),btf.addGlobalFn("pjaxComplete",(()=>newestComments.newestCommentInit(e,t)),e)}}</script><script>window.addEventListener("load",(()=>{const t="artalk-newest-comments",{changeContent:a,generateHtml:e,run:n}=window.newestComments,r=new URLSearchParams({site_name:"清羽飞扬",limit:"5"});n(t,(async n=>{try{const s=await fetch(`https://atk.liushen.fun/api/v2/stats/latest_comments?${r}`),o=await s.json(),{avatarCdn:c,avatarDefault:i}=await(async()=>{const t=t=>t.startsWith("d=")?t:`d=${t}`;try{const a=await fetch("https://atk.liushen.fun/api/v2/conf"),e=await a.json(),{mirror:n,params:r,default:s}=e.frontend_conf.gravatar;return{avatarCdn:n,avatarDefault:t(r||s)}}catch(a){return console.error(a),{avatarCdn:"",avatarDefault:t("")}}})(),l=o.data.map((t=>({avatar:c&&t.email_encrypted?`${c}${t.email_encrypted}?${i}`:"",content:a(t.content_marked),nick:t.nick,url:t.page_url,date:t.date})));btf.saveToLocal.set(t,JSON.stringify(l),10/1440),e(l,n)}catch(t){console.log(t),n.textContent="无法获取评论，请确认相关配置是否正确"}}))}))</script><script src="/config/memos/memos.js"></script><script id="canvas_nest" defer color="128,128,128" opacity="0.7" zindex="-1" count="99" mobile="false" src="https://jsd.liiiu.cn/npm/butterfly-extsrc@1.1.4/dist/canvas-nest.min.js"></script><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/aplayer@1.10.1/dist/APlayer.min.css" media="print" onload='this.media="all"'><script src="https://jsd.liiiu.cn/npm/aplayer@1.10.1/dist/APlayer.min.js"></script><script src="https://jsd.liiiu.cn/npm/meting@2.0.1/dist/Meting.min.js"></script><script src="https://jsd.liiiu.cn/npm/pjax@0.2.8/pjax.min.js"></script><script>(()=>{window.pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"],cacheBust:!1,analytics:!1,scrollRestoration:!1});const e=e=>{e&&Object.values(e).forEach((e=>e()))};document.addEventListener("pjax:send",(()=>{btf.removeGlobalFnEvent("pjaxSendOnce"),btf.removeGlobalFnEvent("themeChange");const t=document.body.classList;t.contains("read-mode")&&t.remove("read-mode"),e(window.globalFn.pjaxSend)})),document.addEventListener("pjax:complete",(()=>{btf.removeGlobalFnEvent("pjaxCompleteOnce"),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),n=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(n)),e.parentNode.replaceChild(t,e)})),e(window.globalFn.pjaxComplete)})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404")}))})()</script><script async data-pjax="" src="/config/busuanzi/busuanzi.js"></script><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><hr><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div><script src="https://jsd.liiiu.cn/npm/algoliasearch@5.8.1/dist/lite/builds/browser.umd.min.js"></script><script src="https://jsd.liiiu.cn/npm/instantsearch.js@4.75.0/dist/instantsearch.production.min.js"></script><script src="/js/search/algolia.js?v=5.0.0"></script></div></div><div class="needEndHide" id="nav-music"><div id="nav-music-hoverTips" onclick="liuMusic.musicToggle()">音乐已暂停</div><meting-js id="13597135963" server="netease" type="playlist" mutex="true" preload="none" data-lrctype="0" order="random" volume="0.8" api="https://met.liiiu.cn/meting/api?server=:server&amp;type=:type&amp;id=:id&amp;r=:r"></meting-js></div><script data-pjax="">function butterfly_swiper_injector_config(){var a=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),a.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/4bb33804/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/04/08/67f49876a62e5.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-04-08</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/4bb33804/&quot;);" href="javascript:void(0);" alt="">PaddleYOLO训练自己的数据集</a><div class="blog-slider__text">近期一直在研究毕业设计，在其中，我涉及到了PaddleYOLO的训练和部署，在网上的教程较少，经过不断努力，我也算是跑出来了，所以在这里分享出来做个记录，防止下次使用又忘记了怎么搞。</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/4bb33804/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/5f71a4b1/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/04/27/680dc7916ef34.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-04-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/5f71a4b1/&quot;);" href="javascript:void(0);" alt="">耗子面板和DPanel简单体验</a><div class="blog-slider__text">最近毕业设计临近尾声，代码也敲完了，目前就剩稍微的调优，就可以开始写论文啦！在闲暇时间，我也尝试部署了一些不一样的面板程序，总感觉1panel稍微有些复杂，很多功能并用不上，比如GPU，下面简单分享一下我的体验。</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/5f71a4b1/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/40702a0d/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/05/06/6819cd4532457.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-05-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/40702a0d/&quot;);" href="javascript:void(0);" alt="">本地实现HEXO文章AI摘要</a><div class="blog-slider__text">五一假期结束啦！这五天啥也没干，就在宿舍敲代码，都快无聊死了，恰逢找到了一些免费API，就自己实现一个AI摘要吧！利用API生成摘要文本放在文章头部，再通过hexo进行渲染就好啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/40702a0d/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/7915ee6b/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/05/25/6832cc105bc41.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-05-25</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/7915ee6b/&quot;);" href="javascript:void(0);" alt="">数据库可视化WEB工具对比</a><div class="blog-slider__text">最近迁移服务器，并且搞了一个1P专业版玩玩，感觉效果很不错，想找一个管理数据库的服务，其中看了phpmyadmin等一些知名项目，但是都不太符合我的要求，最后经过筛选，找到了比较合适的，分享给大家！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/7915ee6b/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/caee2d9f/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/04/18/68024a618942b.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-04-18</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/caee2d9f/&quot;);" href="javascript:void(0);" alt="">美化你的RSS订阅地址</a><div class="blog-slider__text">近期天天忙着毕业设计，冷落了站点文章的更新，最近也终于算是快要搞完了，于是开始捣鼓一些好玩的东西，在浏览阮一峰大佬的周刊时，了解到了RSS也能美化，折腾了一下，没想到还真实现了，在此分享一下。</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/caee2d9f/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>')}for(var elist="null".split(","),cpage=location.pathname,epage="/",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://jsd.liiiu.cn/npm/swiper@11.1.14/swiper-bundle.min.js"></script><script defer data-pjax="" src="/config/swiper/swiper_init.js"></script><script src="https://jsd.liiiu.cn/npm/live2d-widget@^3.1.3/lib/L2Dwidget.min.js"></script><script>L2Dwidget.init({pluginModelPath:"assets/",model:{scale:1,hHeadPos:.5,vHeadPos:.618,jsonPath:"/live2dw/assets/tororo.model.json"},display:{superSample:2,width:250,height:500,position:"left",hOffset:-20,vOffset:-90},mobile:{show:!1,scale:.5},react:{opacityDefault:.7,opacityOnHover:.2},log:!1,pluginJsPath:"lib/",pluginRootPath:"live2dw/",tagMode:!1})</script></body></html>